package com.joysuch.wwyt.app.controller;

import com.joysuch.wwyt.bp.bean.BpEmergencyContingencyPlansBean;
import com.joysuch.wwyt.bp.enums.RegulationDocumentTypes;
import com.joysuch.wwyt.bp.service.BpEmergencyContingencyPlanService;
import com.joysuch.wwyt.core.common.ajax.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author xsx
 * @version 1.0
 * @date 2022/9/16 16:48
 */
@RestController
@RequestMapping("/bp/app/wwyt/bp-emergency-contingency-plan")
@CrossOrigin
@Api(tags = "应急物资")
@Slf4j
public class AppContingencyPlanController {

    @Autowired
    private BpEmergencyContingencyPlanService bpEmergencyContingencyPlanService;

    @GetMapping("/pagePlan")
    @ApiOperation(value = "分页展示预案")
    public ResultBean pagePlan(Pageable page, BpEmergencyContingencyPlansBean.SearchPlanBean condition) {
        try {
            log.info("app查询预案列表");
            condition.setState(RegulationDocumentTypes.AUDIT_PASS.getId()+"");
            Page<BpEmergencyContingencyPlansBean> data = bpEmergencyContingencyPlanService.pagePlan(page, condition);
            return ResultBean.pageData(data.getContent(), data.getTotalElements());
        } catch (Exception e) {
            return ResultBean.fail(101, "分页查询失败");
        }
    }

    @GetMapping("/getPlan")
    @ApiOperation(value = "查看预案")
    public ResultBean getPlan(Long id) {
        try {
            BpEmergencyContingencyPlansBean pBean = bpEmergencyContingencyPlanService.getPlan(id);
            return ResultBean.success(pBean);
        } catch (Exception e) {
            return null;
        }
    }


}
